// This is a content script.  It executes inside the context of the Reddit page
// loaded into the panel and has access to that page's window object and other
// global objects (although the page does not have access to globals defined by
// this script unless they are explicitly attached to the window object).
//
// This content script is injected into the context of the Reddit page
// by the Panel API, which is accessed by the main add-on script in lib/main.js.
// See that script for more information about how the panel is created.
function log(msg){
    CNL.sendMessage({method: "log", arg: msg});
}
log("cnl loaded!");
$(window).click(function (e) {
    if (isEventActivateCNL(e)){
        //Note: in CnlSelection, we use e.rangeParent, e.rangeOffset
        //to detect the clickedWord.
        //But only FF have those properties (not Chrome, not jQuery,..)
        log(["clicked!", e.originalEvent]);
        CnlSearch.search(e.originalEvent);
        return false;//to stopPropagation & preventDefault
    }
    else if(isEventDeactivateCNL(e))
        CnlSearch.hide();
});
function isEventActivateCNL(e){
    return e.button == 2 && e.shiftKey;
}
function isEventDeactivateCNL(e){
    return e.button == 0 && ! CnlSearch.isClickInsideFrame(e);
}
